-- NewsPaperController

local NewsPaperView = import("..views.NewsPaperView")
local NewsPaperDetailsView = import("..views.NewsPaperDetailsView")

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ControllerBase)

function ClassRef:ctor(data)
    self.super.ctor(self, data)
end

function ClassRef:init()
end

function ClassRef:removeListeners()
    self.super.removeListeners(self)
end

function ClassRef:onEvent(eventName, data)
end

function ClassRef:listEvent()
    return {}
end

function ClassRef:openView(data)
    if cc.isDead(self._view) then
        self._view = NewsPaperView.new(app.mvc.VIEWTYPE_BLUR, data)
        self._view:onCloseView(handler(self, self.closeView))
        self._view:onClearView(handler(self, self.clearView))
        self._view:onOperate(handler(self, self.onOperate))
    end
    self:addChild(self._view)
    self._view:show()
    self._view:refreshNewsPaper()
end

function ClassRef:closeView(data)
    if self._view then
        self:removeChild(self._view, data)
        self:clearView()
    end
end

function ClassRef:clearView()
    if self._view then
        self._view = nil
    end
end

function ClassRef:openDetailsView(data)
    self._detailsView = NewsPaperDetailsView.new()
    self._detailsView:onCloseView(function(sender)
        UIHandler:removePopupUiByKey(sender:getViewName())
    end)
    UIHandler:addPopupUi(self._detailsView, self._detailsView:getViewName())
    self._detailsView:show()
    self._detailsView:refresh(data)
end

-------------------------------------------------------


-------------------------------------------------------
function ClassRef:onOperate(op, data)
    print("NewsPaperController:onOperate op = " .. op)
    if op == "openDetailsView" then
        self:openDetailsView(data)
    end
end

return ClassRef